<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class CUtilities extends CApplicationComponent {

    public function CheckAndParseDateFromDB($stringDate) {

        $date = CDateTimeParser::parse($stringDate, Yii::app()->params['dateDBParse']);
        if ((!empty($date))) {  //termasuk jika return not false
            $dataTanggal = date(Yii::app()->params['dateFormatPHP'], $date);
            return $dataTanggal;
        } else {
            return false;
        }
    }

    public function CheckAndParseDateTimeFromDB($stringDate) {

        $date = CDateTimeParser::parse($stringDate, Yii::app()->params['dateDBParse']);
        if ((!empty($date))) {  //termasuk jika return not false
            $dataTanggal = date(Yii::app()->params['dateFormatPHP'], $date);
            return $dataTanggal;
        } else {
            return false;
        }
    }

    public function CheckAndFormatFromForm($stringDate) {

        $tanggal = CDateTimeParser::parse($stringDate, Yii::app()->params['dateToParse']);
        if (!empty($tanggal)) {
            $tanggal = date(Yii::app()->params['dateFormatPHPDB'], $tanggal);
            return $tanggal;
        } else {
            return null;
        }
    }

    public function getCurrentDateTimeDBFormat() {
        $tanggal = date(Yii::app()->params['dateFormatPHPDB']);
        return $tanggal;
    }

}

?>
